package com.gdit.zax.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.Constant;
import com.gdit.zax.dao.StartPicDao;
import com.gdit.zax.entitys.StartPic;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.O;

public class GetStartImage extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		Connection conn = DBUtil.getConnection();
		if (conn==null) {
			O.printFail(response, 1000, "数据库连接失败!");
			return;
		}
		
		DAOFactory dao  = DAOFactory.init(conn, request, response);
		StartPicDao sdao = dao.getStartPicDao();
		StartPic pic = sdao.getStartPic();
		if (pic==null) {
			O.printFail(response,1, "暂无启动界面图片!");
		} else {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", pic.getId());
			map.put("type", pic.getType());
			map.put("path", Constant.WEBRoot + pic.getPath());
			
			O.printSuccess(response, map);
		}
		
		
		
		
	}

}
